package com.fxc.redisTest;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.Objects;

@RunWith(SpringRunner.class)
@SpringBootTest
public class RedisTest {

    @Autowired
    private RedisTemplate<Object,Object> redisTemplate;

    @Test
    public void testRedisTemplate(){

        // 1.获取用来操作String类型数据的ValueOperations对象
        ValueOperations<Object, Object> operations = redisTemplate.opsForValue();

        // 2.借助ValueOperations对象存入数据
        String key = "goods";
        String values = "morning";
        operations.set(key,values);

        // 3.尝试读取刚才设置的数据
        Object readValue = operations.get(key);
        System.out.println(readValue);
    }

}
